using Crawler.DataServices.Persistence.UnitOfWork;
using Crawler.Domain.DataEntities;
using Crawler.DomainServices.DataServices;
using StructureMap;

namespace Crawler.DataServices.Repositories
{
	internal class CrawlingSessionsRepository : ICrawlingSessionRepository
	{
		public void Save(CrawlingSession data)
		{
			using (var uoc = ObjectFactory.GetInstance<IUnitOfWork>())
			{
				uoc.Session.SaveOrUpdate(data);
				uoc.Commit();
			}

		}

		public CrawlingSession Get(string sessionId)
		{
			using (var uoc = ObjectFactory.GetInstance<IUnitOfWork>())
			{
				return uoc.Session.QueryOver<CrawlingSession>().Where(x => x.SessionId == sessionId).SingleOrDefault();
			}
		}
	}
}